//
//  SendComLogicHandle.m
//  NLProjectFrameworkDemo
//
//  Created by iosdeveloper on 2020/4/29.
//  Copyright © 2020 yj_zhang. All rights reserved.
//

#import "SendComLogicHandle.h"
#import "ChatHandleCommonLogic.h"
#import "CommonHeader.h"
@implementation SendComLogicHandle
+(MantisCellJosonData*)sendMessagePrepareWithCellJosnData:(NSString*)type by:(NSString*)by{
   MantisCellJosonData*cellJosonData=[MantisCellJosonData new];
   cellJosonData.type=type;
   cellJosonData.by=by;
    
    return cellJosonData;
    
}

+(MantisTextCellConetentData*)getCellContenModelFromBuildModel:(WelcomeJsonData*)buildModel proModel:(MatinsIMinitModel*)starModel type:(NSString*)type{
    
    MantisTextCellConetentData*contentModel=[MantisTextCellConetentData new];
     contentModel.type=type;//默认发送文本消息，若是其他类型消息单独传该参数
     contentModel.uid=buildModel.payload.uid;
     contentModel.companyId=starModel.companyId;
     contentModel.chatId=buildModel.payload.chatId;
     contentModel.agentId=buildModel.payload.agentId;
     contentModel.projectId=starModel.projectId;
    contentModel.buId=starModel.buId;
    contentModel.channelId=buildModel.payload.channelId;
    contentModel.serviceGroupId=buildModel.payload.serviceGroup;
     double timer =[[NSString jk_UUIDTimestamp]doubleValue];
     contentModel.timestamp=[NSNumber numberWithDouble:timer];
    
    return contentModel;
}


+(MantisTextCellData*)getCellDataFrom:(NSString*)inputStr json:(MantisCellJosonData*)jsonData{
    MantisTextCellData *cellData = [MantisTextCellData new];
    cellData.isMyself=YES;
    cellData.content=inputStr;
   
    cellData.innerMessage = [[TIMMessage alloc] init];
    TIMCustomElem * custom_elem = [[TIMCustomElem alloc] init];
    custom_elem.data =jsonData.mj_JSONData;
    [cellData.innerMessage addElem:custom_elem];
    return cellData;
}

+(MantisTextCellSubContentData*)getChoiceCellDataFrom:(MantisTextCellSubContentData*)btnData json:(MantisCellJosonData*)jsonData{
    
    MantisTextCellSubContentData *cellData = btnData;
     cellData.isMyself=YES;
    
    
     cellData.innerMessage = [[TIMMessage alloc] init];
     TIMCustomElem * custom_elem = [[TIMCustomElem alloc] init];
     custom_elem.data =jsonData.mj_JSONData;
     [cellData.innerMessage addElem:custom_elem];
     return cellData;
    
}


+(MantisTextCellData*)sendDifferentMessaeWith:(NSString*)sendType chatModel:(WelcomeJsonData*)chatModel myModel:(MatinsIMinitModel*)myModel contentType:(NSString*)contentType{
    
    //组装外层
    MantisCellJosonData*offlineModel = [self sendMessagePrepareWithCellJosnData:sendType by:vendor1Str];
    //组装内层content
    MantisTextCellConetentData*contentModel=[self getCellContenModelFromBuildModel:chatModel proModel:myModel type:contentType];
    offlineModel.content=contentModel;

    MantisTextCellData*cellData =[self getCellDataFrom:@"" json:offlineModel];
    return cellData;
}
+(MantisImageMessageCellData *)getPicMessagefromchatModel:(WelcomeJsonData*)chatModel myModel:(MatinsIMinitModel*)myModel picData:(NSDictionary*)data{
    ManitsFileResultModel*fileModel = [ManitsFileResultModel mj_objectWithKeyValues:data];
    
    MantisCellJosonData*cellJosonData=[SendComLogicHandle sendMessagePrepareWithCellJosnData:SDK_MSG by:vendor1Str];//组装外层消息
    //组装Json消息
    MantisTextCellConetentData*contentModel=[SendComLogicHandle getCellContenModelFromBuildModel:chatModel proModel:myModel type:@"IMG"];
    contentModel.msg=fileModel.data;
    cellJosonData.content=contentModel;
    
    //组装发送消息
    MantisImageMessageCellData *cellData = [MantisImageMessageCellData new];
    cellData.content=contentModel.msg;
    cellData.isMyself=YES;
    
    cellData.innerMessage = [[TIMMessage alloc] init];
    TIMCustomElem * custom_elem = [ChatHandleCommonLogic getCustomElemModel:cellJosonData.mj_JSONData];
    [cellData.innerMessage addElem:custom_elem];
    //赋值给celldata cell展示需要用值
    cellData.imgUrl=fileModel.data;
    return cellData;

}

+(MantisTextCellData*)sendPreReadMessageWith:(NSString*)inputStr  chatModel:(WelcomeJsonData*)chatModel myModel:(MatinsIMinitModel*)myModel{
    //组装外层
    MantisCellJosonData*offlineModel = [self sendMessagePrepareWithCellJosnData:SDK_MSG_INPUTTING by:vendor1Str];
    //组装内层content
    MantisTextCellConetentData*contentModel=[self getCellContenModelFromBuildModel:chatModel proModel:myModel type:SDK_MSG_INPUTTING];
    offlineModel.content=contentModel;
    contentModel.msg=inputStr;

    MantisTextCellData*cellData =[self getCellDataFrom:inputStr json:offlineModel];
    return cellData;
}




@end
